﻿using System;
using System.Linq;
using wojilu.Apps.Qycms.Domain;
using wojilu.Apps.Qycms.Interface;

namespace wojilu.Apps.Qycms.Service
{
    public class ConfigsService : IConfigsService
    {
        public String GetValue(String valname)
        {
            Configs config = Configs.find("valname=:v").set("v", valname).first();
            if (config == null) return String.Empty;
            return config.value;
        }

        public Int32 GetCount()
        {
            return Configs.count();
        }

        public String GetTextName(String valname)
        {
            var config = Configs.find("valname=:v").set("v", valname).first();
            if (config == null) return String.Empty;
            var bottonname = config.bottonname;
            var strArray = bottonname.SplitString(",");
            foreach (var strArray1 in strArray.Select(t => t.SplitString("|")).Where(strArray1 => strArray1[0] == config.value))
            {
                return strArray1[1];
            }
            return string.Empty;
        }

        public String GetBottonName(String valname)
        {
            var config = Configs.find("valname=:v").set("v", valname).first();
            if (config != null) return config.bottonname;
            return String.Empty;
        }

    }
}
